home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C08 / Safecons.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  578 b   |  22 lines

  1. //: C08:Safecons.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Using const for safety
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. const int i = 100;  // Typical constant
  11. const int j = i + 10; // Value from const expr
  12. long address = (long)&j; // Forces storage
  13. char buf[j + 10]; // Still a const expression
  14.  
  15. int main() {
  16.   cout << "type a character & CR:";
  17.   const char c = cin.get(); // Can't change
  18.   const char c2 = c + 'a';
  19.   cout << c2;
  20.   // ...
  21. } ///:~
  22.